package com.example.homework;

import androidx.appcompat.app.AppCompatActivity;

    import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.text.DecimalFormat;


public class HW2 extends AppCompatActivity {
    TextView out;
    EditText edit1;
    EditText edit2;
    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        out = (TextView) findViewById(R.id.txt);
        edit1 = (EditText) findViewById(R.id.inp1);
        edit2 = (EditText) findViewById(R.id.inp2);
        Button btn = (Button) findViewById(R.id.btn);


    }


    public void btn(View v) {
        Log.i("main", "onClick msg....");
        String weight = edit1.getText().toString();
        String height = edit2.getText().toString();
        double W = Double.parseDouble(weight);
        double H = Double.parseDouble(height);
        double bim = W / (H * H);

        String advice = "  ";
        if (bim < 18.5) {
            advice = "过轻";
        } else if (bim <= 23.9) {
                advice = "正常";
            } else if (bim <= 27.9) {
                advice = "超重";
            } else if (bim >= 28) {
                advice = "肥胖";
            }


        DecimalFormat dFormat = new DecimalFormat("#.00");
        String BIM=dFormat.format(bim);

        System.out.println("您的BIM指数为：" + BIM + " " + "您的体质" + advice);
    }
}

